using Godot;

#pragma warning disable CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑添加 'required' 修饰符或声明为可以为 null。

namespace MyCraft2;

[Tool]
public partial class Player
{
    private Cube _headMeshInstance;
    private Cube _bodyMeshInstance;
    private Cube _armLeftMeshInstance;
    private Cube _armRightMeshInstance;
    private Cube _legLeftMeshInstance;
    private Cube _legRightMeshInstance;


    private Texture2D _skin;

    [Export]
    public Texture2D Skin
    {
        get => _skin;
        set
        {
            _skin = value;
            if (!_isReady) return;
            _headMeshInstance.Texture =
                _bodyMeshInstance.Texture =
                    _armLeftMeshInstance.Texture =
                        _armRightMeshInstance.Texture =
                            _legLeftMeshInstance.Texture =
                                _legRightMeshInstance.Texture = value;
        }
    }

    private void SkinReady()
    {
        _headMeshInstance = (FindChild("Head") as Cube)!;
        _bodyMeshInstance = (FindChild("Body") as Cube)!;
        _armLeftMeshInstance = (FindChild("ArmLeft") as Cube)!;
        _armRightMeshInstance = (FindChild("ArmRight") as Cube)!;
        _legLeftMeshInstance = (FindChild("LegLeft") as Cube)!;
        _legRightMeshInstance = (FindChild("LegRight") as Cube)!;

        _headMeshInstance.Texture =
            _bodyMeshInstance.Texture =
                _armLeftMeshInstance.Texture =
                    _armRightMeshInstance.Texture =
                        _legLeftMeshInstance.Texture =
                            _legRightMeshInstance.Texture = _skin;
    }
}